package com.cuitrip.component.para.ui;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.cuitrip.component.para.model.ExistStylePara;
import com.cuitrip.component.para.model.FullStylePara;
import com.cuitrip.component.para.model.Para;
import com.cuitrip.component.para.model.TimPara;
import com.cuitrip.business.tripservice.ui.IconTextView;
import com.cuitrip.service.R;
import com.lab.adapter.BaseHolderView;
import com.lab.adapter.IAdapterData;

import butterknife.ButterKnife;
import butterknife.Bind;


/**
 * 段落的holderview
 * Created by ak
 */
public class ParaHolderView extends BaseHolderView {

    @Bind(R.id.para_text)
    protected TextView mTextTitle;

    @Bind(R.id.circle_icon)
    protected IconTextView mCircleIcon;

    @Bind(R.id.para_content)
    protected TextView mTextContent;

    @Bind(R.id.para_tick)
    protected IconTextView mParaTick;

    @Bind(R.id.top_line)
    protected View topLine;

    @Bind(R.id.bottom_line)
    protected View bottomLine;

    private boolean showTopLine;

    private boolean showBottomLine;

    private View rightLine;

    public ParaHolderView(Context context) {
        super(context, R.layout.para_textview_standard);
    }

    private void addRightLine() {
        rightLine = new View(mContext);
        rightLine.setBackgroundColor(getResources().getColor(R.color.ganshi_ded8d7));
        FrameLayout.LayoutParams rightLineLayoutParams = new FrameLayout.LayoutParams(1, ViewGroup.LayoutParams.MATCH_PARENT);
        rightLineLayoutParams.gravity = Gravity.RIGHT;
        rightLine.setLayoutParams(rightLineLayoutParams);
        addView(rightLine);
    }

    @Override
    public void initView(View rootView) {
        this.setClickable(true);
        ButterKnife.bind(this);
    }

    public void setCircleIconSize(float circleSize) {
        mCircleIcon.setTextSize(circleSize);
    }
    public void setCircleIconSize(int typedValue,float circleSize) {
        mCircleIcon.setTextSize(typedValue,circleSize);
    }
    public void setCircleIconColor(int color) {
        mCircleIcon.setTextColor(color);
    }

    public void setTextColor(int color){
        mTextTitle.setTextColor(color);
    }

    public void setShowTopLine(boolean showTopLine) {
        this.showTopLine = showTopLine;
    }

    public void setShowBottomLine(boolean showBottomLine) {
        this.showBottomLine = showBottomLine;
    }

    @Override
    public void bindData(final IAdapterData data, final int position) {
        if (data instanceof Para) {
            if (data instanceof TimPara) {
                mCircleIcon.setVisibility(INVISIBLE);
                mTextTitle.setVisibility(GONE);
                mTextContent.setVisibility(VISIBLE);
                mTextContent.setTextSize(15.f);
                mParaTick.setVisibility(GONE);
                TimPara timPara = (TimPara) data;
                mTextContent.setText(timPara.getText());
            } else if (data instanceof ExistStylePara) {
                mCircleIcon.setVisibility(VISIBLE);
                mTextTitle.setVisibility(VISIBLE);
                mTextContent.setVisibility(GONE);
                ExistStylePara existStylePara = (ExistStylePara) data;
                if(existStylePara.getHeadColor()>0){
                    mTextTitle.setTextColor(getResources().getColor(existStylePara.getHeadColor()));
                }
                if(existStylePara.getCotentColor()>0){
                    mTextContent.setTextColor(getResources().getColor(existStylePara.getCotentColor()));
                }
                mTextTitle.setText(existStylePara.getText() + ":");
                if (existStylePara.isExist()) {
                    mParaTick.setVisibility(VISIBLE);
                } else {
                    mParaTick.setVisibility(GONE);
                }
            } else if (data instanceof FullStylePara) {
                mCircleIcon.setVisibility(VISIBLE);
                mTextTitle.setVisibility(VISIBLE);
                mTextContent.setVisibility(VISIBLE);
                mTextContent.setTextSize(17.f);
                mParaTick.setVisibility(GONE);
                FullStylePara fullStylePara = (FullStylePara) data;
                if (fullStylePara.getHeadColor()>0){
                    mTextTitle.setTextColor(getResources().getColor(fullStylePara.getHeadColor()));
                }
                if (fullStylePara.getContentColor()>0){
                    mTextContent.setTextColor(getResources().getColor(fullStylePara.getContentColor()));
                }
                mTextTitle.setText(fullStylePara.getText() + ":");
                mTextContent.setText(fullStylePara.getContent());
            } else {
                Para para = (Para) data;
                mCircleIcon.setVisibility(VISIBLE);
                mTextTitle.setVisibility(VISIBLE);
                mTextContent.setVisibility(GONE);
                mParaTick.setVisibility(GONE);
                mTextTitle.setText(para.getText());
            }
        }
        if (showTopLine) {
            topLine.setVisibility(VISIBLE);
        } else {
            topLine.setVisibility(GONE);
        }
        bottomLine.setVisibility(showBottomLine ? VISIBLE : INVISIBLE);
    }


}
